home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / Telephone Manager / Stiletto Sources / ModuleSources / HandsetPlayback.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-05  |  5.1 KB  |  186 lines  |  [TEXT/MPS ]

  1. /************************************************************************************************/
  2. /*                                                                                                */
  3. /*    Module Name:    HandsetPlayback                                                                */
  4. /*                                                                                                */
  5. /*    File Name:        HandsetPlayback.c                                                            */
  6. /*                                                                                                */
  7. /*    © Apple Computer, Inc. 1994-1995                                                            */
  8. /*    All Rights Reserved                                                                            */
  9. /*                                                                                                */
  10. /*    Revision History:                                                                            */
  11. /*                                                                                                */
  12. /*        Date        Who                    Modification                                            */
  13. /*                                                                                                */
  14. /*        1994-05-20    Jaakko Railo        Original version                                        */
  15. /*        1994-08-06    Gary Anwyl            Modified GetDNSndInOut to make this module                */
  16. /*        1995-02-01    Jaakko Railo        Modified LinePlayback to make this module                */
  17. /*                                                                                                */
  18. /************************************************************************************************/
  19.  
  20. /****************************************** DESCRIPTION ******************************************
  21.  
  22.     This module uses the StandardFile interface to get the name of a file
  23.     containing an 'snd ' 128 resource. It then plays the sound asynchronously
  24.     to the handset until the user presses the mouse button or the
  25.     sound is finished playing. If the compile time option SND_RESOURCE is undefined
  26.     then the sound is taken from an AIFF file instead of a sound resource.
  27.  
  28. *************************************************************************************************/
  29.  
  30. /******************************************** HEADERS *******************************************/
  31.  
  32. #include "Sound.h"
  33. #include "SoundInput.h"
  34. #include "Events.h"
  35. #include "Resources.h"
  36. #include "TextUtils.h"
  37. #include "Types.h"
  38.  
  39. #ifndef __TELEPHONES__
  40. #include "Telephones.h"
  41. #endif
  42.  
  43. #include "TestModule.h"
  44.  
  45. /****************************************** DEFINITIONS *****************************************/
  46.  
  47. #define    SND_RESOURCE                // define to use 'snd ' resource, undef to use AIFF file
  48. #define kTotalSize        24*1024
  49.  
  50. /****************************************** PROTOTYPES ******************************************/
  51.  
  52. short    GetFileDialog(void);
  53. void     PlaySnd (CHRSPtr paramPtr, Component mySndOut);
  54. void     DoTest (CHRSPtr paramPtr);
  55.  
  56. /************************************************************************************************/
  57. /************************************************************************************************/
  58.  
  59.  
  60. pascal short TestModule (CHRSPtr paramPtr)
  61. {
  62.     short    returnValue = noErr;
  63.     
  64.     if (paramPtr->version <= kTestModuleVersion) {
  65.         
  66.         DoTest (paramPtr);
  67.         
  68.     }
  69.     else
  70.         returnValue = kWrongVersion;
  71.         
  72.     return (returnValue);
  73. }
  74.  
  75.  
  76. short GetFileDialog(void)
  77. {
  78.     StandardFileReply    getReply;
  79.     short                fRefNum;
  80.     SFTypeList            fileTypes = {'AIFF', 0, 0, 0};
  81.     
  82. #ifdef SND_RESOURCE
  83.     StandardGetFile(0, -1, 0, &getReply);
  84.     if (!getReply.sfGood)
  85.         return 0;
  86.     fRefNum = FSpOpenResFile(&getReply.sfFile, fsRdPerm);
  87.     if (fRefNum == -1)
  88.         return 0;
  89. #else
  90.     StandardGetFile(0, 1, fileTypes, &getReply);
  91.     if (!getReply.sfGood)
  92.         return 0;
  93.     err = FSpOpenDF(&getReply.sfFile, fsRdPerm, &fRefNum);
  94.     if (err != noErr)
  95.         return 0;
  96. #endif
  97.         
  98.     return fRefNum;
  99. }
  100.  
  101.  
  102. void PlaySnd (CHRSPtr paramPtr, Component mySndOut)
  103. {
  104.     OSErr            myErr;
  105.     SndChannelPtr    myChan = nil;
  106.     short            myRefNum, curResFile;
  107.     AudioSelection    sel;
  108.     SCStatus        scStatus;
  109.     
  110.     curResFile = CurResFile();
  111.     
  112.     if ((myErr = SndNewChannel (&myChan, kUseOptionalOutputDevice, (long) mySndOut, nil)) != noErr) {
  113.         Print (paramPtr, "### SndNewChannel failed : %d", myErr);
  114.         return;
  115.     }
  116.  
  117.     myRefNum = GetFileDialog();
  118.     if (myRefNum == 0) {
  119.         Print (paramPtr, "### GetFile failed");
  120.         goto errExit1;
  121.     }
  122.         
  123.     Print (paramPtr, "Start of playback");
  124.     sel.unitType = unitTypeSeconds;
  125.     sel.selStart = (0L<<16);
  126.     sel.selEnd = (9999L<<16);
  127. #ifdef SND_RESOURCE
  128.     UseResFile(myRefNum);
  129.     if (Count1Resources('snd ') == 0) {
  130.         Print (paramPtr, "### No 'snd ' resource");
  131.         goto errExit1;
  132.     }
  133.     myErr = SndStartFilePlay(myChan, 0, 128, kTotalSize, nil, &sel, nil, true);
  134. #else
  135.     myErr = SndStartFilePlay(myChan, myRefNum, 0, kTotalSize, nil, &sel, nil, true);
  136. #endif
  137.     if (myErr != noErr) {
  138.         Print (paramPtr, "### SndPlay failed : %d", myErr);
  139.         goto errExit1;
  140.     }
  141.  
  142.     while (1) {
  143.         if (Button())
  144.             break;
  145.             
  146.         myErr = SndChannelStatus(myChan, sizeof(SCStatus), &scStatus);
  147.         if (myErr != noErr) {
  148.             Print (paramPtr, "### SndChannelStatus failed : %d", myErr);
  149.             goto errExit1;
  150.         }
  151.             
  152.         if (!scStatus.scChannelBusy)
  153.             break;
  154.     }
  155.  
  156.     Print (paramPtr, "End of playback");
  157. #ifdef SND_RESOURCE
  158.     CloseResFile(myRefNum);
  159. #endif
  160.  
  161. errExit1:
  162.     UseResFile(curResFile);
  163.     myErr = SndDisposeChannel (myChan, true);
  164. }
  165.  
  166.  
  167. void DoTest (CHRSPtr paramPtr)
  168. {
  169.     TELHandle    termHand = GetCurrentTELHandle (paramPtr);
  170.     OSErr        errCode;
  171.     Component    SndOut;
  172.     
  173.     if ((errCode = TELGetHSSoundOutput (termHand, &SndOut)) == noErr) {
  174.         Print (paramPtr, "TELGetHSSoundOutput --> SndOut = %ld", (long) SndOut);
  175.         PlaySnd (paramPtr, SndOut);
  176.         if ((errCode = TELDisposeHSSoundOutput (termHand, SndOut)) == noErr)
  177.             Print (paramPtr, "TELDisposeHSSoundOutput --> SndOut %ld disposed", (long) SndOut);
  178.         else
  179.             Print (paramPtr, "### TELDisposeHSSoundOutput failed : %d", errCode);
  180.     }
  181.     else
  182.         Print (paramPtr, "### TELGetHSSoundOutput failed : %d", errCode);
  183. }
  184.  
  185.  
  186.